﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 埃氏筛法求素数
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[100];  //用数组元素的值0、1表示对应序号值的素数合数性质
            a[2] = 0;  //2是最小的素数
            int n = 2;
            int t = 0;
            while (t < 101)
            {
                for (int i = 2; i < a.Length; i++)
                {
                    if (i % n == 0 && i != n)
                        a[i] = 1;
                }
                for (int i = 2; i < a.Length; i++)
                {
                    if ((i > n) && a[i] == 0)
                    { 
                        n = i; break;
                    }
                }
                t++;
            }
            Console.Write("2~100中所有的素数为：");
            for (int i = 2; i < a.Length; i++)
            {
                if (a[i] == 0)
                {
                    Console.Write("{0}  ",i);
                }
            }
            Console.ReadLine();
        }
    }
}